package com.cloud.common.utils;

import cn.hutool.core.util.ObjectUtil;
import com.cloud.common.constants.FlowTaskConstants;
import com.cloud.domain.LoginUser;
import com.cloud.utils.SecurityUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 工作流任务类
 */
public class FlowTaskUtils {

    public static String getUserId() {
        return String.valueOf(SecurityUtils.getUserId());
    }

    /**
     * 获取用户组信息
     */
    public static List<String> getCandidateGroup() {
        List<String> list = new ArrayList<>();
        LoginUser user = SecurityUtils.getLoginUser();
        if (ObjectUtil.isNotNull(user)) {
            if (ObjectUtil.isNotEmpty(user.getUser().getRoleIds())) {
                Arrays.asList(user.getUser().getRoleIds()).forEach(role ->
                        list.add(FlowTaskConstants.ROLE_GROUP_PREFIX + role));
            }
            if (ObjectUtil.isNotNull(user.getUser().getDeptId())) {
                list.add(FlowTaskConstants.DEPT_GROUP_PREFIX + user.getUser().getDeptId());
            }
        }
        return list;
    }

}
